package com.wskj.library.dao.impl;

import com.wskj.library.pojo.*;

import com.wskj.library.dao.*;

import java.util.Date;
import java.util.List;

/**
 * advice dao接口类实现类
 * 2018-03-22 T148
 */ 
public class AdviceDaoImpl extends BaseDao implements AdviceDao{

	 @Override
	 public int addAdvice(Advice  advice){
		 String sql="insert into advice (title,content,creater,createTime) values  (?,?,?,?)";
		 Object[] params= {advice.getTitle(),advice.getContent(),advice.getCreater(),new Date()};
		 return super.executeUpdate(sql, params);
	 }
	 @Override
	 public int deleteById(int id){
		 String sql="delete from advice  where aid=? ";
		 Object[] params= {id};
		 return super.executeUpdate(sql, params);
	 }
	 @Override
	 public int updateAdvice(Advice advice){
		 String sql=" update advice  set title=?,content =? , creater=?,status=?  where ai = ? ";
		 Object[] params= {advice.getTitle(),advice.getContent(),advice.getCreater(),advice.getStatus(),advice.getAid()};
		 return super.executeUpdate(sql, params);
	 }
	 @Override
	 public Advice getAdviceById(int id){
		 String sql="select * from advice where aid=? ";
		 Object[] params= {id};
		 return super.queryOne(sql, params,Advice.class);
	 }
	 @Override
	 public  List<Advice>  getAllAdvices(){
		 String sql="select * from advice";
		 Object[] params= null;
		 return super.queryAll(sql, params, Advice.class);
	 }
	
	 
	@Override
	public List<Advice> getAllAdvices(int index, int pagesize) {
		 String sql="select * from advice limit ?,?";
		 Object[] params= {(index-1)*pagesize,pagesize};
		 return super.queryAll(sql, params, Advice.class);
	}
	
	@Override
	public long getCounts() {
		String sql="select count(*) from advice ";
		 Object[] params= null;
		 return super.getCounts(sql, params);
	}
}

